import books4africa.*

class BootStrap {
	
	def springSecurityService

    def init = { servletContext ->
		if (!User.count())
			createUsers()
    }
	
	
    def destroy = {
    }
	
	private void createUsers(){
		def teacher =  new SecRole(authority: 'ROLE_TEACHER').save(failOnError:true)
		def donor = new SecRole(authority:'ROLE_DONOR').save(failOnError:true)
		def both = new SecRole(authority:"ROLE_BOTH").save(failOnError:true)
		def adminRole =  new SecRole(authority: 'ROLE_ADMIN').save(failOnError:true)
		
		User adminUser = new User(
			username:'admin',
			password:'adminUser',
			userType:'Admin',
			enabled:true,
			email:'bradford.pare@maine.edu'
		).save(failOnError:true)
		
		if (!adminUser.authorities.contains(adminRole))
			SecUserSecRole.create adminUser, adminRole, true
		
	}
}
